@echo off
chcp 65001 >nul 2>&1
title DataPlexus Data Lineage System

echo ================================================================
echo                    DataPlexus Startup Script
echo                  Data Lineage Analysis System
echo ================================================================
echo.

:: Check Python
echo [1/4] Checking Python...
python --version >nul 2>&1
if errorlevel 1 (
    echo ERROR: Python not found. Please install Python 3.8+
    echo Download: https://www.python.org/downloads/
    pause
    exit /b 1
)
echo OK: Python is installed

:: Check Node.js
echo [2/4] Checking Node.js...
node --version >nul 2>&1
if errorlevel 1 (
    echo ERROR: Node.js not found. Please install Node.js 16+
    echo Download: https://nodejs.org/
    pause
    exit /b 1
)
echo OK: Node.js is installed

:: Start Backend
echo [3/4] Starting backend service...
cd backend
start "DataPlexus Backend" cmd /k "echo DataPlexus Backend API && echo Port: 8000 && echo API Docs: http://localhost:8000/docs && echo. && python main.py"
cd ..

:: Wait for backend
echo Waiting for backend to start...
timeout /t 3 >nul

:: Start Frontend
echo [4/4] Starting frontend service...
cd frontend
start "DataPlexus Frontend" cmd /k "echo DataPlexus Frontend && echo Port: 3000 && echo URL: http://localhost:3000 && echo. && npm run dev"
cd ..

:: Show completion message
echo.
echo ================================================================
echo                    System Started Successfully!
echo ================================================================
echo.
echo Frontend:     http://localhost:3000
echo Backend API:  http://localhost:8000
echo API Docs:     http://localhost:8000/docs
echo Health Check: http://localhost:8000/health
echo.
echo Note: Two service windows are now running.
echo       Close the windows to stop the services.
echo.
echo Press any key to exit this launcher...
pause >nul

:: Try to open browser
echo Opening browser...
start http://localhost:3000
timeout /t 1 >nul
start http://localhost:8000/docs

exit /b 0
